package com.cy.store.controller;


import com.cy.store.entity.Product;
import com.cy.store.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import util.JsonResult;

import java.util.List;

@RestController
@RequestMapping("products")
public class ProductController extends BaseController{
    @Autowired
    private IProductService iProductService;

    @RequestMapping("hot_list")
    public JsonResult<List<Product>> getHotList(){
        List<Product> list = iProductService.findHotList();
        return new JsonResult<>(Ok,list);
    }

    @GetMapping("{id}/details")
    public JsonResult<Product> getById(@PathVariable("id") Integer id){
        Product data = iProductService.findById(id);
        return new JsonResult<>(Ok,data);
    }

    @RequestMapping("all_list")
    public JsonResult<List<Product>> getAllList(){
        List<Product> list = iProductService.findAllList();
        return new JsonResult<>(Ok,list);
    }


}
